package com.authManager.web.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.authManager.entity.SysMenu;

public class VipAdminMenuData {
	public VipAdminMenuData(List<SysMenu> menuList, Long systemId) {
		if (menuList != null) {
			data = dg(menuList, systemId);
		}
	}

	private List<Map<String, Object>> data = new ArrayList<>();

	public List<Map<String, Object>> getData() {
		return data;
	}

	public void setData(List<Map<String, Object>> data) {
		this.data = data;
	}

	public List<Map<String, Object>> dg(List<SysMenu> list, Long parentId) {
		List<Map<String, Object>> dataList = new ArrayList<>();
		if (list != null && list.size() > 0) {
			for (int i = 0; i < list.size(); i++) {
				SysMenu sysMenu = list.get(i);
				if (parentId == sysMenu.getParentId()) {
					Map<String, Object> map = new HashMap<>();
					map.put("text", sysMenu.getName());
					map.put("icon", "");
					if (StringUtils.isNotBlank(sysMenu.getIcon())) {
						map.put("icon", sysMenu.getIcon());
					}
//					map.put("target", null);
					if(StringUtils.isNotBlank(sysMenu.getPageUrlType()) && !"children_page".equalsIgnoreCase(sysMenu.getPageUrlType())) {
						map.put("target", "_blank");
						if("this_page".equalsIgnoreCase(sysMenu.getPageUrlType())) {
							map.put("target", "_self");
						}
					}
					map.put("href", sysMenu.getPageUrl());
					List<Map<String, Object>> dataTmp = dg(list, list.get(i).getSysMenuId());
					if (dataTmp != null && dataTmp.size() > 0) {
						map.put("subset", dataTmp);
					}
					dataList.add(map);
				}
			}
		}
		return dataList;
	}
}
